/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package piplayer.impl.common;

import java.io.*;
import java.util.*;

/**
 *
 * @author richb
 */
public class Library
{
    
    private DirNode _rootNode;
    
    public static class DirNode implements Comparable<DirNode>
    {
        
        private File _thisDir;
        
        public DirNode getParent()
        {
            return null;
        }
        
        public DirNode getNextDir()
        {
            return this.getParent().getIndexRelativeDirNode(this, 1);
        }
        
        public DirNode getPreviousDir()
        {
            return this.getParent().getIndexRelativeDirNode(this, -1);
        }
        
        public int getNumTracks()
        {
            return 0;
        }
        
        public int getNumDirs()
        {
            return (int) Arrays.asList(this._thisDir.listFiles()).stream().filter(dir -> dir.isDirectory()).count();
        }
        
        public FileNode getFirstContainedTrack()
        {
            return null;
        }
        
        public DirNode getFirstContainedDir()
        {
            if (this.getNumDirs() > 0)
            {
                Optional<File> optF = Arrays.asList(this._thisDir.listFiles()).stream().filter((File f) -> f.isDirectory()).sorted().findFirst();
                
                try
                {
                    final DirNode d = new DirNode();
                    d._thisDir = optF.get();
                    return d;
                }
                catch (Exception e)
                {
                    throw new Error(e);
                }
            }
            else
            {
                return null;
            }
        }
        
        public DirNode getIndexRelativeDirNode(DirNode d, int index)
        {
            return null;
        }
        
        public FileNode getIndexRelativeFileNode(FileNode f, int index)
        {
            return null;
        }
        
        public DirNode getIndexAbsDirNode(DirNode d, int index)
        {
            return null;
        }
        
        public FileNode getIndexAbsFileNode(FileNode f, int index)
        {
            return null;
        }

        @Override
        public int compareTo(DirNode t)
        {
            return this._thisDir.getName().compareTo(t._thisDir.getName());
        }
        
    }
    
    public static class FileNode
    {
        private DirNode _parentDir;
        
        public String getFullPathToFile()
        {
            return null;
        }
        
        public DirNode getContainingDirectory()
        {
            return this._parentDir;
        }
        
        public FileNode getNextTrack()
        {
            return null;
        }
        
        public FileNode getPreviousTrack()
        {
            return null;
        }
    }
    
    public void build(String rootDir)
    {
        
    }
    
    public int getNumTracks()
    {
        return 0;
    }
    
    public DirNode getRootDirNode()
    {
        return null;
    }
    
    public FileNode retrieveByString(String rootRelativePathToFile)
    {
        return null;
    }
    
}
